/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bff.mpd.musicjukebox.ui.components;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JTextField;

/**
 *
 * @author Music
 */
public class RoundedTextField extends JTextField {

    private Color borderColor = Color.BLACK;
    private float alpha;

    public RoundedTextField() {
        // We must be non-opaque since we won't fill all pixels.
        // This will also stop the UI from filling our background.
        setOpaque(false);

        // Add an empty border around us to compensate for
        // the rounded corners.
        setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));

        /*
        alpha = 1.0f;

        MouseListener ml = new MouseAdapter() {

            public void mouseEntered(MouseEvent e) {
                alpha = 1.0f;
                repaint();
                // take focus
                requestFocus();
            }

            public void mouseExited(MouseEvent e) {
                // if there is text entered, dont make the textfield semi-transparent
                if ("".equals(getText()) || getText() == null) {
                    return;
                }
                alpha = 0.5f;
                repaint();
                // give something else focus, so the textfield no longer has focus
                if (getParent() != null) {
                    getParent().requestFocus();
                }
            }
        };

        addMouseListener(ml);
         */
    }

    protected void paintComponent(Graphics g) {
        int width = getWidth();
        int height = getHeight();

        // Paint a rounded rectangle in the background.
        g.setColor(getBackground());
        g.fillRoundRect(0, 0, width, height, height, height);

        // Now call the superclass behavior to paint the foreground.
        super.paintComponent(g);
    }

    /*
    protected void paintComponent(Graphics g) {
        int w = getWidth();
        int h = getHeight();
        RenderingHints renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

        Graphics2D g2d = (Graphics2D) g;
        AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
        g2d.setComposite(alphaComposite);
        g2d.setRenderingHints(renderHints);
        g2d.setColor(getBackground());
        g2d.fillRoundRect(0, 0, w, h, h, h);

        if (borderColor != null) {
            g2d.setColor(borderColor);
            g2d.drawRoundRect(0, 0, w - 1, h - 1, h - 1, h - 1);
        }

        super.paintComponent(g);
    }
     */
}
